export default {
  namespaced: true,
  state () {
    return {
      goodList: [
        {
          name: '诸葛亮',
          price: 1000,
          num: 2,
          checked: false
        },
        {
          name: '蔡文姬',
          price: 1500,
          num: 1,
          checked: false
        },
        {
          name: '妲己',
          price: 2000,
          num: 1,
          checked: false
        },
        {
          name: '鲁班',
          price: 2200,
          num: 1,
          checked: true
        }
      ]
    }
  },
  getters: {
    // Cost (state) {
    //   return state.good
    // },
    Price (state) {
      // console.log(state)
      return state.goodList.filter(item => item.checked).reduce((sum, item) => sum + item.num * item.price, 0)
    }

  },
  mutations: {
    setCount (state, payload) {
      state.goodList[payload.index].num = payload.num
    },
    DelItem (state, payload) {
      state.goodList.splice(payload.index, 1)
    },
    ClickFn (state, payload) {
      state.goodList[payload.index].checked = !state.goodList[payload.index].checked
    }
  },
  actions: {
    async updateCount (context, payload) {
      await context.commit('setCount', payload)
    },
    async DelFn (context, payload) {
      await context.commit('DelItem', payload)
    },
    async CheckedAll (context, payload) {
      await context.commit('AllChange', payload)
      // console.log(payload)
    },
    async Fn (context, payload) {
      await context.commit('ClickFn', payload)
    }
  },
  modules: {
  }
}
